import { Component, Injector } from '@angular/core';
import { EntityDtoOfInt64, HomePageServiceProxy, PictureDto } from '@shared/service-proxies/service-proxies';
import { NotifyService } from '@abp/notify/notify.service';
import { AppConsts } from '@shared/AppConsts';
import { AppComponentBase } from '@shared/common/app-component-base';

@Component({
  selector: 'app-picture',
  templateUrl: './picture.component.html',
  styleUrls: ['./picture.component.css']
})
export class PictureComponent extends AppComponentBase {

  pictures: Array<PictureDto[]>;

  constructor(
    injector: Injector,
    private _notifyService: NotifyService,
    private _homepage: HomePageServiceProxy
  ) {
    super(injector);
    this.getPicture();
  }

  getPicture(): void {
    this.pictures = new Array<PictureDto[]>();
    this._homepage.getPictures().subscribe(result => {
      result.items.forEach(item => {
        item.url = AppConsts.remoteServiceBaseUrl + item.url;
      });
      let picture: PictureDto[] = Array<PictureDto>();
      let i = 0;
      result.items.forEach(item => {
        picture.push(item);
        i++;
        if (i === 3) {
          i = 0;
          this.pictures.push(picture);
          picture = new Array<PictureDto>();
        }
      });

    });
  }

}
